using UnityEngine;
using System.Collections;

/// \class  gkTextureAnimationLoader
/// \brief  Load a texture animation based on a root name with number incrementation
[AddComponentMenu("GK/Engine/Core/Animation/Texture/gkTextureAnimationLoader")]
public class gkTextureAnimationLoader : MonoBehaviour 
{
	/// The texture animation to load
	public gkTextureAnimation TextureAnimationToLoad;
	
	/// The root name of the images used for the animation
	public string ImagesRootName = "RootName";
	
	/// The number of zeros in the image name
	public string ImageNumberFormat = "{0:00000}";
	
	/// The number of the start image
	public int NumImageStart = 0;
	
	/// The number of the end image
	public int NumImageEnd = 0;
	
	/// The current frame index
	private int m_iCurrentFrameIndex;
	
	/// \brief Use this for initialization
	void Start () 
	{
		// Load the textures of the animation
		LoadAnimationTextures();
	}
	
	/// \brief Load the textures of the animation
	void LoadAnimationTextures()
	{
		string strCurrentImagePath = "";
		
		// Load each frame one by one in order
		TextureAnimationToLoad.AnimationTexturesSequence = new Texture[NumImageEnd - NumImageStart + 1];
		for(int i = NumImageStart; i <= NumImageEnd; i++)
		{
			// Construct the current image name
			strCurrentImagePath = "TextureAnimations/"
				+ ImagesRootName + string.Format(ImageNumberFormat, i);
			
			//Load the textures
			TextureAnimationToLoad.AnimationTexturesSequence[i - NumImageStart] = 
				Resources.Load(strCurrentImagePath) as Texture;
		}
	}
}
